import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
    meta: { title: '首页' }
  },
  {
    path: '/students',
    name: 'StudentList',
    component: () => import('@/views/StudentList.vue'),
    meta: { title: '学生管理' }
  },
  {
    path: '/students/add',
    name: 'StudentAdd',
    component: () => import('@/views/StudentForm.vue'),
    meta: { title: '新增学生' }
  },
  {
    path: '/students/edit/:id',
    name: 'StudentEdit',
    component: () => import('@/views/StudentForm.vue'),
    meta: { title: '编辑学生' }
  },
  {
    path: '/analysis',
    name: 'Analysis',
    component: () => import('@/views/Analysis.vue'),
    meta: { title: 'AI成绩分析' }
  },
  {
    path: '/classification',
    name: 'Classification',
    component: () => import('@/views/Classification.vue'),
    meta: { title: '分类统计分析' }
  },
  {
    path: '/classes',
    name: 'ClassList',
    component: () => import('@/views/ClassList.vue'),
    meta: { title: '班级管理' }
  },
  {
    path: '/classes/add',
    name: 'ClassAdd',
    component: () => import('@/views/ClassForm.vue'),
    meta: { title: '新增班级' }
  },
  {
    path: '/classes/edit/:id',
    name: 'ClassEdit',
    component: () => import('@/views/ClassForm.vue'),
    meta: { title: '编辑班级' }
  },
  {
    path: '/classes/detail/:id',
    name: 'ClassDetail',
    component: () => import('@/views/ClassDetail.vue'),
    meta: { title: '班级详情' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title || '学生管理系统'} - AI辅助学生信息管理系统`
  next()
})

export default router
